<!DOCTYPE html>
<html>
<head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta http-equiv="Expires" CONTENT="0">
        <meta http-equiv="Cache-Control" CONTENT="no-cache">
        <meta http-equiv="Pragma" CONTENT="no-cache">
    <title>蛋糕商城</title>
<link rel="stylesheet" type="text/css" href="../easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="../easyui/themes/icon.css">
<link rel="stylesheet" type="text/css" href="../easyui/demo/demo.css">
<script type="text/javascript" src="../easyui/jquery.min.js"></script>
<script type="text/javascript" src="../easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../js/sha1.js"></script>
<script type="text/javascript" src="../uploadjs/vendor/jquery.ui.widget.js"></script>
<script type="text/javascript" src="../uploadjs/jquery.iframe-transport.js"></script>
<script type="text/javascript" src="../uploadjs/jquery.fileupload.js"></script>
</head>
<body  style="background:#B3DFDA;text-align:center">
<center>
<div style="margin:20px 0"></div>
<div class="easyui-panel" title="注册新用户" style="width:700px">
<div style="padding:10px 60px 20px 60px">
<form id="ff" method="post">
<table cellpadding="5">
<tr><td>用户名:</td><td><input  class='easyui-textbox' type='text' name='userName' id='userName' value='' data-options="required:false"/></td></tr>
<tr><td>密码:</td><td><input  class='easyui-textbox' type='password' name='password' id='password' value='' data-options="required:false"/></td></tr>
<tr><td>确认密码:</td><td><input  class='easyui-textbox' type='password' name='confirmPassword' id='confirmPassword' value='' data-options="required:false"/></td></tr>
<tr><td>用户名:</td><td><input  class='easyui-textbox' type='text' name='userName' id='userName' value='' data-options="required:false"/></td></tr>
<tr><td>名字:</td><td><input  class='easyui-textbox' type='text' name='firstName' id='firstName' value='' data-options="required:false"/></td></tr>
<tr><td>姓:</td><td><input  class='easyui-textbox' type='text' name='lastName' id='lastName' value='' data-options="required:false"/></td></tr>
<tr><td>电子邮件:</td><td><input  class='easyui-textbox' type='text' name='email' id='email' value='' data-options="required:false"/></td></tr>
<tr><td>是否管理员:</td><td><input class='easyui-radio' type='radio' name='isadmin' id='isadmin' value='true' checked='true'/>True<input type='radio' class='easyui-radio' name='isadmin' id='isadmin' value='false'/>False</td></tr>
<tr><td>性别:</td><td><input  class='easyui-textbox' type='text' name='gender' id='gender' value='' data-options="required:false"/></td></tr>
<tr><td>地址:</td><td><input  class='easyui-textbox' type='text' name='address' id='address' value='' data-options="required:false"/></td></tr>
<tr><td>电话:</td><td><input  class='easyui-textbox' type='text' name='phone' id='phone' value='' data-options="required:false"/></td></tr>
<tr><td>描述:</td><td><textarea  class='easyui-textarea' type='text' name='description' id='description' data-options="required:false" cols='20' rows='4'></textarea></td></tr>
<tr><td>照片:</td><td><img name='photo' id='photo' width='500px' src='../css/images/blank.jpg'><br>
<input id="addUserPhotoFileupload" type="file" name="files[]" data-url="../loginController/addUploadUserPhoto"><br></td></tr>
<tr><td>活跃:</td><td><input class='easyui-radio' type='radio' name='active' id='active' value='true' checked='true'/>True<input type='radio' class='easyui-radio' name='active' id='active' value='false'/>False</td></tr>
</table>
</form>
<div style="text-align:center;padding:5px">
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="registerUser()">注册</a>
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearForm()">清除</a>
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="window.location='index.html'">转到登录</a>
</div>
</div>
</div>
</center>
<script>
$(function () {
    $('#addUserPhotoFileupload').fileupload({
            autoUpload: true,
            dataType: 'json',
            async: false,
            success: function(data, textStatus) {
            if (data.success == true){
                $("#ff").find("#photo").prop("src","data:image/png;base64,"+data.data)
            }
            },
            progressall: function (e, data) {
                var progress = parseInt(data.loaded / data.total * 100, 10);
            },
        });
});
function registerUser(){
        if (isBlank($("#ff").find("#userName").val())||isBlank($("#ff").find("#password").val())||isBlank($("#ff").find("#confirmPassword").val())){
            $.messager.alert("错误","必须字段为空！","error");
            return;
        }
if ($("#ff").find("#password").val()!=$("#ff").find("#confirmPassword").val()){
            $.messager.alert("错误","密码不匹配！","error");
            return;
        }
        $.ajax({
            type: "post",
            url: "../loginController/registerUser",
            data: JSON.stringify({
                userName:$("#ff").find("#userName").textbox("getValue"),
                password:hex_sha1($("#ff").find("#password").textbox("getValue")),
                userName:$("#ff").find("#userName").val(),
                firstName:$("#ff").find("#firstName").val(),
                lastName:$("#ff").find("#lastName").val(),
                email:$("#ff").find("#email").val(),
                isadmin:parseBoolean($("#ff").find("input[name='isadmin']:checked").val()),
                gender:$("#ff").find("#gender").val(),
                address:$("#ff").find("#address").val(),
                phone:$("#ff").find("#phone").val(),
                description:$("#ff").find("#description").val(),
                photo:$("#ff").find("#photo").val(),
                active:parseBoolean($("#ff").find("input[name='active']:checked").val()),
            }),
            dataType: 'json',
            contentType:"application/json;charset=UTF-8",
            success: function(data, textStatus) {
                if (data.success) {
                    $('#ff').form('clear');
                    $.messager.alert("信息","注册新用户成功！","info");
                } else if (data.success == false){
                    $.messager.alert("错误","注册用户失败！","error");
                }
                },
            complete : function(XMLHttpRequest, textStatus) {
            },
            error : function(XMLHttpRequest,textStatus,errorThrown) {
                alert("Error:"+textStatus);
                alert(errorThrown.toString());
            }
        });
}

function parseBoolean(val){
    if (val == undefined|| val == null) return false;
    var isInt = /^(-}+)?\d+$/.test(val);
    if (isInt&& val == "0") return false;
    else if (isInt&& val == "1") return true;
    else if (val.toLowerCase() == "false") return false;
    else if (val.toLowerCase() == "true") return true;
    else if (val.toLowerCase() == "f") return false;
    else if (val.toLowerCase() == "t") return true;
    else if (val.toLowerCase() == "n") return false;
    else if (val.toLowerCase() == "y") return true;
    else if (val.toLowerCase() == "no") return false;
    else if (val.toLowerCase() == "yes") return true;
    else return "";
}

function parseBooleanInt(val){
    var b = parseBoolean(val);
    if (b==undefined||b==null) return 0;
    else if (b==true) return 1;
    else return 0;
}

function isBlank(val){
    if (val == undefined|| val == null || val == "" || val== "0" || val == 0) return true;
    else return false;
}

</script>
</body>
</html>
